﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Clinica_Frba
{
    public partial class DecisionCancelar : Form
    {
        Conexion sqlCon = Conexion.getInstance();
        Utility util = Utility.getInstance();
        CancelarAtencionMedico medicoForm;
        CancelarAtencionPaciente pacienteForm;  

        public DecisionCancelar()
        {
            InitializeComponent();
        }

        private void DecisionCancelar_Load(object sender, EventArgs e)
        {
            this.Text = "Cancelar Turnos";
        }

        public void showCancelarForm()
        {
            SqlDataReader reader;          

            // Check si es Paciente
            reader = sqlCon.execQuery("SELECT Id_Paciente FROM b_sharp.Pacientes WHERE Usuario = '" + util.getUserName() + "';");

            if (reader.Read())
            {
                pacienteForm = new CancelarAtencionPaciente();
                pacienteForm.idAfiliado = reader.GetInt32(0);
                pacienteForm.Show();
                reader.Close();
                this.Close();
                return;
            }

            //Check si es Medico
            reader = sqlCon.execQuery("SELECT id_medico FROM b_sharp.Medicos WHERE id_usuario = '" + util.getUserName() + "';");

            if (reader.Read())
            {
                medicoForm = new CancelarAtencionMedico();
                medicoForm.idMed = reader.GetInt32(0);
                medicoForm.Show();
                reader.Close();
                this.Close();
                return;
            }

            this.Show();
        }

        private void buttonMedico_Click(object sender, EventArgs e)
        {
            medicoForm = new CancelarAtencionMedico();
            medicoForm.Show();
            this.Close();
        }

        private void buttonPaciente_Click(object sender, EventArgs e)
        {
            pacienteForm = new CancelarAtencionPaciente();
            pacienteForm.Show();
            this.Close();
        }
    }
}
